import java.lang.reflect.Array;
import java.util.Arrays;

//<T> 标志位：代表当前类是泛型类
class MyArry2<T>{
    //public Object[] array = new Object[10];->会存在一个Object的数组
    public T[] array = (T[])new Object[10];

    public T getPos(int pos){
        return array[pos];
    }
    public void setVal(int pos,T val){
        this.array[pos] = val;
    }
    public T[] getArray(){
        return array;
    }
}
class MyArray3<T>{
    public T[] array;
    public MyArray3(){

    }
    public MyArray3(Class<T> clazz, int capacity){
        array = (T[])Array.newInstance(clazz,capacity);
    }
    public T getPos(int pos){
        return  this.array[pos];
    }
    public void setVal(int pos,T val){
        this.array[pos] = val;
    }
    public T[] getArray(){
        return array;
    }
}

public class Test2 {
    public static void main(String[] args) {
        MyArray3<Integer> myArray3 = new MyArray3<>(Integer.class,10);
        myArray3.setVal(0,10);
        Integer[] tmp = myArray3.getArray();
        System.out.println(Arrays.toString(tmp));
    }
    public static void main3(String[] args) {
        MyArry2<Integer> myArry2 = new MyArry2<Integer>();
        myArry2.setVal(0,10);
        Integer[] tmp = myArry2.getArray();
        System.out.println(Arrays.toString(tmp));
    }

    public static void main2(String[] args){
        //1.<>里面指定了类型，说明此时这个类里面，只能放这个数据类型的数据
        MyArry2<String> myArry = new MyArry2<String>();
        myArry.setVal(0,"abc");
        myArry.setVal(1,"hello");

        String s = (String) myArry.getPos(1);
        System.out.println(s);

        MyArry2<Integer> myArry2 = new MyArry2<Integer>();
        myArry2.setVal(0,10);
        myArry2.setVal(1,13);
        myArry2.setVal(2,60);

    }
}
